﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class Promotions
    {
        private readonly Chain.IDAL.Promotions dal = new Chain.IDAL.Promotions();

        public int Add(Chain.Model.Promotions model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.Promotions> DataTableToList(DataTable dt)
        {
            List<Chain.Model.Promotions> list = new List<Chain.Model.Promotions>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.Promotions item = new Chain.Model.Promotions();
                    if ((dt.Rows[i]["PromotionsID"] != null) && (dt.Rows[i]["PromotionsID"].ToString() != ""))
                    {
                        item.PromotionsID = int.Parse(dt.Rows[i]["PromotionsID"].ToString());
                    }
                    if ((dt.Rows[i]["PromotionsTitle"] != null) && (dt.Rows[i]["PromotionsTitle"].ToString() != ""))
                    {
                        item.PromotionsTitle = dt.Rows[i]["PromotionsTitle"].ToString();
                    }
                    if ((dt.Rows[i]["PromotionsStart"] != null) && (dt.Rows[i]["PromotionsStart"].ToString() != ""))
                    {
                        item.PromotionsStart = DateTime.Parse(dt.Rows[i]["PromotionsStart"].ToString());
                    }
                    if ((dt.Rows[i]["PromotionsEnd"] != null) && (dt.Rows[i]["PromotionsEnd"].ToString() != ""))
                    {
                        item.PromotionsEnd = DateTime.Parse(dt.Rows[i]["PromotionsEnd"].ToString());
                    }
                    if ((dt.Rows[i]["PromotionsMemLevel"] != null) && (dt.Rows[i]["PromotionsMemLevel"].ToString() != ""))
                    {
                        item.PromotionsMemLevel = int.Parse(dt.Rows[i]["PromotionsMemLevel"].ToString());
                    }
                    if ((dt.Rows[i]["PromotionsType"] != null) && (dt.Rows[i]["PromotionsType"].ToString() != ""))
                    {
                        item.PromotionsType = int.Parse(dt.Rows[i]["PromotionsType"].ToString());
                    }
                    if ((dt.Rows[i]["PromotionsTime"] != null) && (dt.Rows[i]["PromotionsTime"].ToString() != ""))
                    {
                        item.PromotionsTime = DateTime.Parse(dt.Rows[i]["PromotionsTime"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int PromotionsID)
        {
            return this.dal.Delete(PromotionsID);
        }

        public bool DeleteList(string PromotionsIDlist)
        {
            return this.dal.DeleteList(PromotionsIDlist);
        }

        public bool Exists(int PromotionsID)
        {
            return this.dal.Exists(PromotionsID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public Chain.Model.Promotions GetModel(int PromotionsID)
        {
            return this.dal.GetModel(PromotionsID);
        }

        public List<Chain.Model.Promotions> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public DataSet GetPromotionsInfo(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetPromotionsInfo(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.Promotions model)
        {
            return this.dal.Update(model);
        }
    }
}

